package dlwntk6545.swing.outline;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JCheckBox;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JPasswordField;


/*
		
		스윙 기본 컴퍼넌트(레이블, 버튼)
		JLabel			: 제목을 표시할때 사용 (편집불가)
						: 텍스트를 표시하는데 주로 사용하지만, 이미지를 표시하는데에도 사용할 수 있음
		JButton			: 클릭가능한 버튼 표시, 처리를 유발하는 역활 담당
						: 클릭했을때 실행하는 코드를 제공하려면 event listener 에 연결해야 함
						: 버튼은 단순 텍스트나 아이콘 버튼 또는 아이콘 텍스트를 만들 수 있음
		JCheckBox		: 클릭가능한 확인 버튼 표시 클릭할때마다 선택/비선택의 상태로 전환
						    보기 중 다중 선택이 가능함, 단독으로 사용도 가능
		JRadioButton	: 클릭가능한 확인 버튼 표시
						    단독 사용불가, 그룹화해서 그중 하나만 선택
		setFont			: 
		setIcon			: 
		
 */


public class J19_BasicComponentFrame extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField;
	
	int i;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					J19_BasicComponentFrame frame = new J19_BasicComponentFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public J19_BasicComponentFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.WEST);
		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
		
		final JCheckBox check1 = new JCheckBox("New check box");
		i = 0;
		check1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				i += 1;
				System.out.println(i);
			}
		});
		
		
		
		panel.add(check1);
		
		final JCheckBox check2 = new JCheckBox("New check box");
		panel.add(check2);
		
		final JCheckBox check3 = new JCheckBox("New check box");
		panel.add(check3);
		
		JButton btnNewButton = new JButton("New button");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean chk1 = check1.isSelected();
				boolean chk2 = check2.isSelected();
				boolean chk3 = check3.isSelected();
				
				String msg = chk1 + "/" + chk2 + "/" + chk3;
				
				JOptionPane.showMessageDialog(null, msg);
				
			}
		});
		panel.add(btnNewButton);
		
		JPanel panel_1 = new JPanel();
		contentPane.add(panel_1, BorderLayout.NORTH);
		
		JLabel lblNewLabel = new JLabel("New label");
		panel_1.add(lblNewLabel);
		
		ButtonGroup radios = new ButtonGroup();
		
		JPanel panel_2 = new JPanel();
		contentPane.add(panel_2, BorderLayout.EAST);
		panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.PAGE_AXIS));
		
		final JRadioButton radio1 = new JRadioButton("New radio button");
		panel_2.add(radio1);
		final JRadioButton radio2 = new JRadioButton("New radio button");
		panel_2.add(radio2);
		final JRadioButton radio3 = new JRadioButton("New radio button");
		panel_2.add(radio3);
		
		
		
		JPanel panel_3 = new JPanel();
		contentPane.add(panel_3, BorderLayout.SOUTH);
		
		
		
		
		radios.add(radio1);
		radios.add(radio2);
		radios.add(radio3);
		panel_2.add(radio1);
		panel_2.add(radio2);
		panel_2.add(radio3);
		JButton btn = new JButton("라디오버튼 확인");
		radios.add(btn);
		
		JButton btnNewButton_1 = new JButton("New button");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean rdbtn1 = radio1.isSelected();
				boolean rdbtn2 = radio2.isSelected();
				boolean rdbtn3 = radio3.isSelected();
				String msg = rdbtn1 + "/" + rdbtn2 + "/" + rdbtn3;
				JOptionPane.showMessageDialog(null, msg);
				
			}
		});
		panel_2.add(btnNewButton_1);
		
		
		JPanel panel_4 = new JPanel();
		contentPane.add(panel_4, BorderLayout.CENTER);
		panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.Y_AXIS));
		
		textField = new JTextField();
		panel_4.add(textField);
		textField.setColumns(10);
		
		passwordField = new JPasswordField();
		passwordField.setEchoChar('*');
		panel_4.add(passwordField);
		
		final JTextArea textArea = new JTextArea();
		panel_4.add(textArea);
		
		JButton btnNewButton_2 = new JButton("New button");
		panel_3.add(btnNewButton_2);
		btnNewButton_2.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				String msg = textField.getText();
				msg += "\n" + new String(passwordField.getPassword());
				msg += "\n" + textArea.getText();
				
				JOptionPane.showMessageDialog(null, msg);
				
			}
		});
		
		
		
	}

}
